# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

class Migration(SchemaMigration):

    def forwards(self, orm):
        
        # Adding model 'Experiment'
        db.create_table('experiment_experiment', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=50)),
            ('protocol', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['protocol.Protocol'])),
            ('details', self.gf('django.db.models.fields.CharField')(max_length=250)),
        ))
        db.send_create_signal('experiment', ['Experiment'])

        # Adding model 'Race'
        db.create_table('experiment_race', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=50)),
        ))
        db.send_create_signal('experiment', ['Race'])

        # Adding model 'SubjectCode'
        db.create_table('experiment_subjectcode', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=50)),
        ))
        db.send_create_signal('experiment', ['SubjectCode'])

        # Adding model 'Subject'
        db.create_table('experiment_subject', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('experiment', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['experiment.Experiment'])),
            ('gender', self.gf('django.db.models.fields.CharField')(max_length=1)),
            ('handedness', self.gf('django.db.models.fields.CharField')(max_length=1)),
            ('ethnicity', self.gf('django.db.models.fields.CharField')(max_length=1)),
            ('notes', self.gf('django.db.models.fields.TextField')()),
        ))
        db.send_create_signal('experiment', ['Subject'])

        # Adding M2M table for field race on 'Subject'
        db.create_table('experiment_subject_race', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('subject', models.ForeignKey(orm['experiment.subject'], null=False)),
            ('race', models.ForeignKey(orm['experiment.race'], null=False))
        ))
        db.create_unique('experiment_subject_race', ['subject_id', 'race_id'])

        # Adding M2M table for field other on 'Subject'
        db.create_table('experiment_subject_other', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('from_subject', models.ForeignKey(orm['experiment.subject'], null=False)),
            ('to_subject', models.ForeignKey(orm['experiment.subject'], null=False))
        ))
        db.create_unique('experiment_subject_other', ['from_subject_id', 'to_subject_id'])

        # Adding M2M table for field codes on 'Subject'
        db.create_table('experiment_subject_codes', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('subject', models.ForeignKey(orm['experiment.subject'], null=False)),
            ('subjectcode', models.ForeignKey(orm['experiment.subjectcode'], null=False))
        ))
        db.create_unique('experiment_subject_codes', ['subject_id', 'subjectcode_id'])

        # Adding model 'Phone'
        db.create_table('experiment_phone', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('number', self.gf('django.contrib.localflavor.us.models.PhoneNumberField')(max_length=20)),
        ))
        db.send_create_signal('experiment', ['Phone'])

        # Adding model 'Email'
        db.create_table('experiment_email', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('email', self.gf('django.db.models.fields.EmailField')(max_length=100)),
        ))
        db.send_create_signal('experiment', ['Email'])

        # Adding model 'Contact'
        db.create_table('experiment_contact', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('subject', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['experiment.Subject'], unique=True)),
            ('first_name', self.gf('django.db.models.fields.CharField')(max_length=50)),
            ('last_name', self.gf('django.db.models.fields.CharField')(max_length=100)),
            ('address_1', self.gf('django.db.models.fields.CharField')(max_length=200)),
            ('address_2', self.gf('django.db.models.fields.CharField')(max_length=200)),
            ('city', self.gf('django.db.models.fields.CharField')(max_length=50)),
            ('state', self.gf('django.contrib.localflavor.us.models.USStateField')(max_length=2)),
            ('zip_code', self.gf('django.db.models.fields.CharField')(max_length=5)),
            ('allow_contact', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('notes', self.gf('django.db.models.fields.TextField')()),
        ))
        db.send_create_signal('experiment', ['Contact'])

        # Adding M2M table for field phones on 'Contact'
        db.create_table('experiment_contact_phones', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('contact', models.ForeignKey(orm['experiment.contact'], null=False)),
            ('phone', models.ForeignKey(orm['experiment.phone'], null=False))
        ))
        db.create_unique('experiment_contact_phones', ['contact_id', 'phone_id'])

        # Adding M2M table for field emails on 'Contact'
        db.create_table('experiment_contact_emails', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('contact', models.ForeignKey(orm['experiment.contact'], null=False)),
            ('email', models.ForeignKey(orm['experiment.email'], null=False))
        ))
        db.create_unique('experiment_contact_emails', ['contact_id', 'email_id'])

        # Adding model 'CompensationType'
        db.create_table('experiment_compensationtype', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
        ))
        db.send_create_signal('experiment', ['CompensationType'])

        # Adding model 'Location'
        db.create_table('experiment_location', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=150)),
        ))
        db.send_create_signal('experiment', ['Location'])

        # Adding model 'SubjectSession'
        db.create_table('experiment_subjectsession', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('subject', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['experiment.Subject'])),
            ('session', self.gf('django.db.models.fields.PositiveIntegerField')(default=1)),
            ('age', self.gf('django.db.models.fields.PositiveIntegerField')()),
            ('date_tested', self.gf('django.db.models.fields.DateField')()),
            ('compensation', self.gf('django.db.models.fields.PositiveIntegerField')()),
            ('compensation_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['experiment.CompensationType'])),
            ('location', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['experiment.Location'])),
            ('consenter', self.gf('django.db.models.fields.related.ForeignKey')(related_name='session_consenter', to=orm['lab.Researcher'])),
            ('consented', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('completed', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('adverse_event', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('notes', self.gf('django.db.models.fields.TextField')()),
        ))
        db.send_create_signal('experiment', ['SubjectSession'])

        # Adding unique constraint on 'SubjectSession', fields ['subject', 'session']
        db.create_unique('experiment_subjectsession', ['subject_id', 'session'])

        # Adding M2M table for field researchers on 'SubjectSession'
        db.create_table('experiment_subjectsession_researchers', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('subjectsession', models.ForeignKey(orm['experiment.subjectsession'], null=False)),
            ('researcher', models.ForeignKey(orm['lab.researcher'], null=False))
        ))
        db.create_unique('experiment_subjectsession_researchers', ['subjectsession_id', 'researcher_id'])


    def backwards(self, orm):
        
        # Removing unique constraint on 'SubjectSession', fields ['subject', 'session']
        db.delete_unique('experiment_subjectsession', ['subject_id', 'session'])

        # Deleting model 'Experiment'
        db.delete_table('experiment_experiment')

        # Deleting model 'Race'
        db.delete_table('experiment_race')

        # Deleting model 'SubjectCode'
        db.delete_table('experiment_subjectcode')

        # Deleting model 'Subject'
        db.delete_table('experiment_subject')

        # Removing M2M table for field race on 'Subject'
        db.delete_table('experiment_subject_race')

        # Removing M2M table for field other on 'Subject'
        db.delete_table('experiment_subject_other')

        # Removing M2M table for field codes on 'Subject'
        db.delete_table('experiment_subject_codes')

        # Deleting model 'Phone'
        db.delete_table('experiment_phone')

        # Deleting model 'Email'
        db.delete_table('experiment_email')

        # Deleting model 'Contact'
        db.delete_table('experiment_contact')

        # Removing M2M table for field phones on 'Contact'
        db.delete_table('experiment_contact_phones')

        # Removing M2M table for field emails on 'Contact'
        db.delete_table('experiment_contact_emails')

        # Deleting model 'CompensationType'
        db.delete_table('experiment_compensationtype')

        # Deleting model 'Location'
        db.delete_table('experiment_location')

        # Deleting model 'SubjectSession'
        db.delete_table('experiment_subjectsession')

        # Removing M2M table for field researchers on 'SubjectSession'
        db.delete_table('experiment_subjectsession_researchers')


    models = {
        'auth.group': {
            'Meta': {'object_name': 'Group'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
        },
        'auth.permission': {
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        'auth.user': {
            'Meta': {'object_name': 'User'},
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
        },
        'contenttypes.contenttype': {
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        },
        'experiment.compensationtype': {
            'Meta': {'object_name': 'CompensationType'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        },
        'experiment.contact': {
            'Meta': {'object_name': 'Contact'},
            'address_1': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
            'address_2': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
            'allow_contact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'city': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
            'emails': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['experiment.Email']", 'symmetrical': 'False'}),
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'notes': ('django.db.models.fields.TextField', [], {}),
            'phones': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['experiment.Phone']", 'symmetrical': 'False'}),
            'state': ('django.contrib.localflavor.us.models.USStateField', [], {'max_length': '2'}),
            'subject': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['experiment.Subject']", 'unique': 'True'}),
            'zip_code': ('django.db.models.fields.CharField', [], {'max_length': '5'})
        },
        'experiment.email': {
            'Meta': {'object_name': 'Email'},
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '100'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
        },
        'experiment.experiment': {
            'Meta': {'object_name': 'Experiment'},
            'details': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
            'protocol': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['protocol.Protocol']"})
        },
        'experiment.location': {
            'Meta': {'object_name': 'Location'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
        },
        'experiment.phone': {
            'Meta': {'object_name': 'Phone'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'number': ('django.contrib.localflavor.us.models.PhoneNumberField', [], {'max_length': '20'})
        },
        'experiment.race': {
            'Meta': {'object_name': 'Race'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        'experiment.subject': {
            'Meta': {'object_name': 'Subject'},
            'codes': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['experiment.SubjectCode']", 'symmetrical': 'False'}),
            'ethnicity': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
            'experiment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['experiment.Experiment']"}),
            'gender': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
            'handedness': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'notes': ('django.db.models.fields.TextField', [], {}),
            'other': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'other_rel_+'", 'to': "orm['experiment.Subject']"}),
            'race': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['experiment.Race']", 'symmetrical': 'False'})
        },
        'experiment.subjectcode': {
            'Meta': {'object_name': 'SubjectCode'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        'experiment.subjectsession': {
            'Meta': {'unique_together': "(('subject', 'session'),)", 'object_name': 'SubjectSession'},
            'adverse_event': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'age': ('django.db.models.fields.PositiveIntegerField', [], {}),
            'compensation': ('django.db.models.fields.PositiveIntegerField', [], {}),
            'compensation_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['experiment.CompensationType']"}),
            'completed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'consented': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'consenter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'session_consenter'", 'to': "orm['lab.Researcher']"}),
            'date_tested': ('django.db.models.fields.DateField', [], {}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['experiment.Location']"}),
            'notes': ('django.db.models.fields.TextField', [], {}),
            'researchers': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['lab.Researcher']", 'symmetrical': 'False'}),
            'session': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
            'subject': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['experiment.Subject']"})
        },
        'lab.lab': {
            'Meta': {'object_name': 'Lab'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'path': ('django.db.models.fields.FilePathField', [], {'path': "'/Users/zarrar/Dropbox/sites/accession/filedb/'", 'max_length': '200', 'blank': 'True'}),
            'path_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {'blank': 'True'})
        },
        'lab.researcher': {
            'Meta': {'unique_together': "(('user', 'lab'),)", 'object_name': 'Researcher'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'lab': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lab.Lab']"}),
            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
        },
        'protocol.committee': {
            'Meta': {'object_name': 'Committee'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '20'})
        },
        'protocol.institution': {
            'Meta': {'object_name': 'Institution'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '80'})
        },
        'protocol.protocol': {
            'Meta': {'object_name': 'Protocol'},
            'committee': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['protocol.Committee']"}),
            'date_added': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime.now', 'auto_now_add': 'True', 'blank': 'True'}),
            'date_updated': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime.now', 'auto_now': 'True', 'blank': 'True'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'institution': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['protocol.Institution']"}),
            'lab': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lab.Lab']"}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
            'path': ('django.db.models.fields.FilePathField', [], {'path': "'/Users/zarrar/Dropbox/sites/accession/filedb/'", 'max_length': '200', 'blank': 'True'}),
            'path_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {'blank': 'True'}),
            'protocol_status': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
            'reference_code': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        }
    }

    complete_apps = ['experiment']
